#include <stdio.h>
int a[6], book[6];
void dfs(int step, int n)
{
    int i;
    if (step == n + 1)
    {
        for (i = 1; i <= n; i++)
        {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
    for (i = 1; i <= n; i++)
    {
        if (book[i] == 0)
        {
            book[i] = 1;
            a[step] = i;
            dfs(step + 1, n);
            book[i] = 0;
        }
    }
}

int main()
{
    const int N;
    scanf("%d", &N);
    dfs(1, N);
    return 0;
}
